package org.github.manx98.jlibhac.fs;

import java.io.IOException;

/**
 * @author Manx98
 * @version 1.0
 * @since 2022/10/6 14:47
 */
public class ValueSubStorage extends IStorage {
    private final IStorage baseStorage;
    private final long size;

    public ValueSubStorage() {
        super(0);
        this.baseStorage = null;
        this.size = 0;
    }

    public ValueSubStorage(IStorage subStorage, long offset, long size) {
        super(0);
        this.baseStorage = subStorage.slice(offset, size);
        this.size = size;
    }

    public IStorage getSubStorage() {
        return this.baseStorage.asStorage();
    }

    public void read(long offset, byte[] array) throws IOException {
        read(offset, array, 0, array.length);
    }

    @Override
    public void read(long offset, byte[] destination, int destOffset, int len) throws IOException {
        this.baseStorage.read(offset, destination, destOffset, len);
    }

    @Override
    public long getSize() {
        return size;
    }
}
